Skip to content

fix(webhook): remove dead diff code block that panics on nil namespace metadata#1976

Merged
oliverbaehler merged 1 commit into
projectcapsule:mainfrom
jouve:pr/fix-namespace-webhook-nil-map
Jun 22, 2026
Merged

fix(webhook): remove dead diff code block that panics on nil namespace metadata#1976
oliverbaehler merged 1 commit into
projectcapsule:mainfrom
jouve:pr/fix-namespace-webhook-nil-map

Conversation

@jouve

@jouve jouve commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

In userMetadataHandler.OnUpdate the per-request labels/annotations diff is computed twice. The inline block at the top clones oldNs metadata and diffs it against newNs, but its results are immediately shadowed by the labels, annotations, err := userMetadataForValidation(...) declaration in the tnt.Spec.NamespaceOptions != nil branch, which recomputes the same diff (via metadataForValidation) and is the only version actually passed to validateUserMetadata. The inline block is therefore dead code.

It is also a panic: maps.Clone(oldNs.GetAnnotations()) returns nil for a namespace with no annotations, and the following annotations[key] = value then panics with "assignment to entry in nil map" (same with labels).
This happens when using features like NamespaceOptions.AdditionalMetadataList on a namespace that had none.

The dead block and panic was introduced in a6927c5 (#1947).

Copilot AI review requested due to automatic review settings June 21, 2026 22:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes a redundant, unreachable metadata-diff block in userMetadataHandler.OnUpdate that both duplicated the real validation diff computation and could panic when cloning nil label/annotation maps.

Changes:

  • Deleted the dead inline labels/annotations diff logic in OnUpdate that was immediately shadowed by userMetadataForValidation(...).
  • Eliminated a confirmed nil-map write panic path (maps.Clone(nil) followed by assignment) for namespaces without pre-existing labels/annotations.

…e metadata

In userMetadataHandler.OnUpdate the per-request labels/annotations diff is computed twice. The inline block at the top clones oldNs metadata and diffs it against newNs, but its results are immediately shadowed by the `labels, annotations, err := userMetadataForValidation(...)` declaration in the `tnt.Spec.NamespaceOptions \!= nil` branch, which recomputes the same diff (via metadataForValidation) and is the only version actually passed to validateUserMetadata. The inline block is therefore dead code.

It is also a  panic: `maps.Clone(oldNs.GetAnnotations())` returns nil for a namespace with no annotations, and the following `annotations[key] = value` then panics with "assignment to entry in nil map" (same with labels).
This happens when using features like NamespaceOptions.AdditionalMetadataList on a namespace that had none.

The dead block and panic was introduced in a6927c5 (projectcapsule#1947).

Signed-off-by: Cyril Jouve <jv.cyril@gmail.com>
@jouve jouve force-pushed the pr/fix-namespace-webhook-nil-map branch from 8b8719b to 1d47c28 Compare June 21, 2026 22:48
@oliverbaehler oliverbaehler merged commit 4e9e529 into projectcapsule:main Jun 22, 2026
16 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants